#include "xwrite_task.h"
#include <iostream>

bool XWriteTask::init(const std::string &fileName)
{
    bool ret = true;
    ofs_.open(fileName, std::ios::binary);
    if (!ofs_) {
        std::cerr << "failed to open " << fileName << std::endl;
    } else {
        std::cout << "success open file " << fileName << std::endl;
    }

    return ret;
}

void XWriteTask::handle()
{
    while (!isExit_) {
        auto data = pop();
        ofs_.write((char*)data->data(), data->size());
        if (data->end()) {
            break;
        }
    }
    ofs_.close();
}